package com.katydid.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

@Entity
@NamedQueries({
    @NamedQuery(name = Tag.FIND_ALL, query = "SELECT t FROM Tag t"),
    @NamedQuery(name = Tag.FIND_BY_CATEGORY_NAME, query = "SELECT t from Tag t where t.category.name=:cname")
})
public class Tag {
	public static final String FIND_ALL = "Tag.findAll";
	public static final String FIND_BY_CATEGORY_NAME = "Tag.findByCategoryName";
	
	@Id
	@Column(name = "tag_id")
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_gen")
	private long id;
	
	private String tag;
	
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "tag")
	private List<Note> notes = new ArrayList<Note>();
	
	@ManyToOne
	@Column(name="category_id")
	private Category category;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public List<Note> getNotes() {
		return notes;
	}

	public void setNotes(List<Note> notes) {
		this.notes = notes;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}
	
}
